package com.tbit.uqbike.client.controller;

import com.tbit.uqbike.client.constant.ResponseCode;
import com.tbit.uqbike.client.exception.BaseException;
import com.tbit.uqbike.client.pojo.AdAccountFee;
import com.tbit.uqbike.client.service.VipFeeService;
import com.tbit.uqbike.client.util.Assert;
import com.tbit.uqbike.client.util.OutputUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * 会员卡计费
 *
 * @Author: chen
 * @Description:
 * @Date: 创建于 16:59 2021/5/24
 */
@Controller
@RequestMapping("/vipFee")
public class VipFeeController {

    @Autowired
    private VipFeeService vipFeeService;

    /**
     * 通过主键id获取
     *
     * @param vipId    会员卡id
     * @param session
     * @param request
     * @param response
     */
    @RequestMapping("/getByVipId")
    public void getByVipId(Integer vipId, HttpSession session, HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> map = new HashMap<String, Object>();

        try {
            Assert.notNull(vipId, "-180001", "主键id不能为空");

            AdAccountFee adAccountFee = vipFeeService.getByVipId(vipId);
            map.put(ResponseCode.RET, ResponseCode.SUCC);
            map.put(ResponseCode.DATA, adAccountFee);
        } catch (BaseException e) {
            ResponseCode.printException(map, e, request);
        }

        OutputUtil.renderText(request, response, map);
    }

}
